#ifndef POPUP_SETTINGS_HPP
#define POPUP_SETTINGS_HPP

#include <QtGui>
#include <QSettings>
#include <PopupClientUI.hpp>
#include <PopupCustomButton.hpp>
#include <PopupGui.hpp>

struct PopupSettings : public QSettings
{
private:
  PopupSettings()
  : QSettings("popup-v2", "parameters"), m_savePassword(false) {}

public:
  
  enum SerializeDirection { POPUP_SAVE_TO_FILE, POPUP_READ_FROM_FILE };
  enum PopupSystrayAction { POPUP_SHOW_WINDOW, POPUP_EXIT, POPUP_SWITCH_CLIENT_MODE, POPUP_NO_ACTION };

  virtual ~PopupSettings() {}
  static PopupSettings *instance();
  bool serialize(enum SerializeDirection p_direction);
  
  // Getters
  int serverPort() const;
  const QString & serverName() const;
  const QString & nickname() const;
  const QString & login() const;
  const QString & password() const;
  const QString & temporaryDirectory() const;
  const QString & resourceDirectory() const;
  const QString & browser() const;
  const QString & videoPlayer() const;
  const QString & imageViewer() const;
  const QString & messageDialogStyleSheet() const;
  bool framelessMessageDialog() const;
  Popup::UserMode defaultClientMode() const;
  bool useEmbeddedImageViewer() const;
  bool automaticImageViewerShow() const;
  PopupGui::Position getImageViewerPosition() const;
  bool isImageViewerTransitionFxEnabled() const;
  bool isImageViewerOpacityFxEnabled() const;
  bool isImageViewerZoomFxEnabled() const;
  PopupGui::Transition getImageViewerTransition() const;
  void getImageViewerPosition(QString & p_hpos, QString & p_vpos) const;
  void getImageViewerTransition(QString & p_hEffect, QString & p_vEffect) const;
  bool useFakePrompt() const;
  enum PopupSystrayAction systrayAction(QSystemTrayIcon::ActivationReason p_action) const;
  bool friendsList(const QString & p_name, Popup::UserList & p_list) const;

  QList<QString> friendsListsNames() const;
  const PopupCustomButtonList & customButtons();
  bool addCustomButton(const QString & p_name,
                       const QString & p_icon,
                       const QString & p_media,
                       const QString & p_text);
  PopupCustomButton *customButton(const QString & p_name);
  void deleteCustomButton(const QString & p_name);
  const QString & updateUrl() const;
  int updateCheckDelay() const;
  bool updateEnabled() const;
  const QString & updateProxy() const;
  bool updateProxyEnabled() const;
  bool customFontEnabled() const;
  const QString & customFontName() const;
  int customFontSize() const;
  const QString & customFontColor() const;
  const QString & customFontPrefix() const;
  const QString & customFontSuffix() const;
  bool customFontIsBold() const;
  bool customFontIsItalic() const;
  bool isFuckNotificationEnabled() const;
  bool isLikeNotificationEnabled() const;
  bool isSuckNotificationEnabled() const;
  bool isPoetryNotificationEnabled() const;
  bool isTransfersDialogBoxEnabled() const;
  bool isDisplayAllowed(PopupGui::ReceivedMsgType) const;

  // Setters
  void setServerName(const QString & p_host);
  void setServerPort(int p_port);
  void setNickname(const QString & p_nickname);
  void setLogin(const QString & p_login);
  void setPassword(const QString & p_password);
  void setTemporaryDirectory(const QString & p_dir);
  void setResourceDirectory(const QString & p_dir);
  void setBrowserPath(const QString & p_path);
  void setVideoPlayerPath(const QString & p_path);
  void setImageViewerPath(const QString & p_path);
  void setUseEmbeddedImageViewer(bool p_enabled);
  void setAutomaticImageViewerShow(bool p_enabled);
  void setEnableImageViewerOpacityFx(bool p_enabled);
  void setEnableImageViewerZoomFx(bool p_enabled);
  void setEnableImageViewerTransitionFx(bool p_enabled);
  void setImageViewerPosition(QString posX, QString posY);
  void setImageViewerTransitionFx(QString xEffect, QString yEffect);
  void setUseFakePrompt(bool p_enabled);
  void setDefaultClientMode(Popup::UserMode p_mode);
  void setDefaultClientMode(const QString & p_mode);
  void setMessageDialogStyleSheet(const QString & p_style);
  void setFramelessMessageDialog(bool p_isFrameless);
  void setSystrayAction(QSystemTrayIcon::ActivationReason p_reason,
			PopupSystrayAction p_action);
  void setSavePassword(bool p_save);
  void setFriendsList(const QString & p_name, const Popup::UserList & p_list);
  void setUpdateUrl(const QString & p_url);
  void setUpdateCheckDelay(int p_delay);
  void setUpdateEnabled(bool p_enabled);
  void setUpdateProxy(const QString & p_proxy);
  void setUpdateProxyEnabled(bool p_enabled);
  void setCustomFontEnabled(bool p_enabled);
  void setCustomFontName(const QString & p_name);
  void setCustomFontSize(int p_size);
  void setCustomFontColor(const QString & p_color);
  void setCustomFontIsBold(bool p_isBold);
  void setCustomFontIsItalic(bool p_isBold);
  void setFuckNotificationEnabled(bool p_enabled);
  void setLikeNotificationEnabled(bool p_enabled);
  void setSuckNotificationEnabled(bool p_enabled);
  void setPoetryNotificationEnabled(bool p_enabled);
  void setTransfersDialogBoxEnabled(bool p_enabled);

  // Friends list (de)serialization utilities
  QStringList serializedFriendsLists() const;
  void deserializeFriendsLists(const QStringList & p_lists);

  // Custom buttons utilties
  QStringList serializedButtonsList() const;
  void deserializeButtonsList(const QStringList & p_buttons);

  // Direct accessors/getters
  QByteArray fileDialogState() const;
  void setFileDialogState(const QByteArray & p_state);

  // Defaults
  static const QString MAIN_DIALOG_DEFAULT_STYLESHEET;
  static const QString MESSAGE_DIALOG_DEFAULT_STYLESHEET;

  static QString popupSystrayActionToString(PopupSystrayAction p_action);
  static PopupSystrayAction stringToPopupSystrayAction(const QString & p_string);
  static QString popupPositionToString(PopupGui::Position p_pos);
  static PopupGui::Position popupStringToPosition(const QString & p_string);
  static QString popupTransitionToString(PopupGui::Transition p_pos);
  static PopupGui::Transition popupStringToTransition(const QString & p_string);

private:

  void load();
  void save();
  void updateCustomFont();

  static PopupSettings *m_instance;
  
  QString m_serverName;
  int m_serverPort;
  QString m_nickname;
  QString m_login;
  QString m_password;
  QString m_tempDir;
  QString m_resourceDir;
  QString m_browser;
  QString m_videoplayer;
  QString m_imageviewer;
  QString m_defaultMode;
  QString m_mainDialogStyleSheet;
  QString m_messageDialogStyleSheet;
  bool m_framelessMessageDialog;
  bool m_useEmbeddedImageViewer;
  bool m_automaticImageViewerShow;
  bool m_enableImageViewerOpacityFx;
  bool m_enableImageViewerZoomFx;
  bool m_enableImageViewerTransitionFx;
  PopupGui::Transition m_imageViewerTransition;
  PopupGui::Position m_imageViewerPosition;
  bool m_useFakePrompt;
  bool m_savePassword;
  enum PopupSystrayAction m_lClickAction;
  enum PopupSystrayAction m_rClickAction;
  enum PopupSystrayAction m_mClickAction;
  enum PopupSystrayAction m_ldClickAction;
  std::map<QString, Popup::UserList> m_friendsLists;
  PopupCustomButtonList m_buttonsList;
  QString m_updateUrl;
  int m_updateCheckDelay;
  bool m_updateEnabled;
  QString m_updateProxy;
  bool m_updateProxyEnabled;
  bool m_customFontEnabled;
  QString m_customFontName;
  QString m_customFontColor;
  int m_customFontSize;
  QString m_customFontPrefix;
  QString m_customFontSuffix;
  bool m_customFontIsBold;
  bool m_customFontIsItalic;
  bool m_enableFuckNotification;
  bool m_enableSuckNotification;
  bool m_enableLikeNotification;
  bool m_enablePoetryNotification;
  bool m_enableTransfersDialogBox;
};


#endif // POPUP_SETTINGS_HPP
